<!doctype html>
<html>
<head>
<?php $this->load->view('admin/common_head'); ?>
</head>
<body>
<div class="wrap J_check_wrap">
	<div class="nav">
		<ul class="cc">
			<li <?php if($action == FALSE) echo 'class="current"'; ?>><a href="<?php echo site_url('admin/announce/index'); ?>">公告列表</a></li>
			<li <?php if($action == 'expired') echo 'class="current"'; ?>><a href="<?php echo site_url('admin/announce/index?action=expired'); ?>">过期公告</a></li>
			<li><a href="<?php echo site_url('admin/announce/add'); ?>">+ 添加公告</a></li>
		</ul>
	</div>
	<form class="J_ajaxForm" action="<?php echo site_url('admin/announce/do_vieworder_ajax'); ?>" method="post" accept-charset="utf-8">
		<div class="table_list">
			<table width="100%">
				<colgroup>
					<col width="60" />
					<col width="60" />
					<col />
					<col width="100" />
					<col width="120" />
					<col width="170" />
					<col />
				</colgroup>
				<thead>
					<tr>
						<td><label><input type="checkbox" class="J_check_all" data-direction="x" data-checklist="J_check_x">全选</label></td>
						<td>顺序</td>
						<td>公告标题</td>
						<td>状态</td>
						<td>发布者</td>
						<td>有效时间</td>
						<td>操作</td>
					</tr>
				</thead>
				<tbody id="J_announce_tr">
				<?php
					foreach($announces as $announce)
					{
						$time = strtotime(date('Y-m-d'));
						if($time < $announce['start_date'])
						{
							$status = '<span class="red">待发布</span>';
						}
						if($time >= $announce['start_date'] && $time <= $announce['end_date'])
						{
							$status = '<span class="green">发布中</span>';
						}
						if($time > $announce['end_date'])
						{
							$status = '<span class="gray">已过期</span>';
						}
						$start_date = $announce['start_date'] ? date('Y-m-d', $announce['start_date']) : '-';
						$end_date = $announce['end_date'] ? date('Y-m-d', $announce['end_date']) : '-';
				?>
					<tr>
						<td><input class="J_check" data-xid="J_check_x" data-yid="J_check_y" type="checkbox" name="announceids[]" value="<?php echo $announce['announceid']; ?>" /></td>
						<td><input class="input length_0" type="text" name="vieworders[<?php echo $announce['announceid']; ?>]" value="<?php echo $announce['vieworder']; ?>" /></td>
						<td><?php echo $announce['subject']; ?></td>
						<td><?php echo $status; ?></td>
						<td><?php echo $announce['username']; ?></td>
						<td><?php echo $start_date; ?> 至 <?php echo $end_date; ?></td>
						<td>
							<a href="<?php echo site_url('admin/announce/edit?announceid='.$announce['announceid']); ?>" title="编辑" class="mr10">[编辑]</a>
							<a href="<?php echo site_url('admin/announce/do_del_ajax?announceid='.$announce['announceid']); ?>" title="删除" class="J_ajax_del">[删除]</a>
						</td>
					</tr>
				<?php } ?>
				</tbody>
			</table>
		</div>
	<?php if($announces) { ?>
		<div class="btn_wrap">
			<div class="btn_wrap_pd">
				<label class="mr20"><input type="checkbox" data-checklist="J_check_y" data-direction="y" class="J_check_all" name="checkAll" />全选</label>
				<button type="submit" class="btn btn_submit J_ajax_submit_btn" />提交</button>
				<button type="button" id="J_link_del_all" class="btn">删除</button>
			</div>
		</div>
		<div data-key="true" class="J_page_wrap mb20">
			<?php echo $this->pagination->create_links(); ?>
		</div>
	<?php } ?>
	</form>
</div>
<?php $this->load->view('admin/common_footer'); ?>
<script>
Wind.use('dialog',function() {

	//分类筛选
	var link_tr = $('#J_link_tr > tr');
	$('#J_link_types').on('change', function(){
		link_tr.hide();
		var $this = $(this), v = $this.val();
		if(v) {
			$('.J_link_'+ v).parents('tr').show();
		}else{
			link_tr.show();
		}
	});
	
	//批量删除
	$('#J_link_del_all').on('click', function(e){
		e.preventDefault();
		if(!$('input.J_check:checked').length) {
			Wind.dialog.alert('亲，至少要选定一条公告哦');
			return;
		}
		Wind.dialog({
			message	: '亲，确定删除选定的公告吗？', 
			type	: 'confirm',
			onOk	: function() {
				$('form.J_ajaxForm').ajaxSubmit({
					dataType : 'json',
					url		 : '<?php echo site_url('admin/announce/do_dels_ajax') ?>',
					success	 : function(data, statusText, xhr, $form) {
						if(data.state === 'success') {
							var location = window.location;
							location.href = location.pathname + location.search;
						}else{
							Wind.dialog.alert(data.message);
						}
					}
				});
			}
		});
		
	});
});
</script>
</body>
</html>